package reflect;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

/**
 * 使用反射机制,调用Student的无参构造器,和有参构造器分别实例化对象
 */
public class Test {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {

        Class cls = Class.forName("reflect.Student");
        Object obj = cls.newInstance();
        System.out.println(obj);

        Constructor c = cls.getConstructor(String.class,int.class,char.class);
        Object obj1 = c.newInstance("王五",55,'女');
        System.out.println(obj1);


    }
}
